﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace Ruleweaver.Rules.CheckMethods
{
	public sealed class IsEqualToMethod : CheckMethod
	{
		private readonly object _value;

		public IsEqualToMethod(object value)
		{
			_value = value;
		}

		public object Value { get; private set; }

		protected override bool SupportsTargetType(Type targetType)
		{
			return true;
		}

		protected override MethodInfo GetMethod(Type targetType, Type checkType)
		{
			return typeof(Checkable)
				.GetMethods(BindingFlags.Public | BindingFlags.Static)
				.Where(method => method.Name == "IsEqualTo")
				.Where(method => method.GetParameters().Length == 2)
				.First()
				.MakeGenericMethod(targetType);
		}

		protected override IEnumerable<object> GetCheckArguments(Type targetType)
		{
			yield return _value;
		}
	}
}